package cn.com.callback

import cn.com.elite.EliteBean
import cn.com.elite.Util
import cn.com.kh.KHDBConfig
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import java.time.Instant
/**
 *
 * @Title: aipHSTRecycle_operation_timing
 * @Description:华盛证券 人员回收定时任务查询接口
 * @author: xrm
 * @date 2022-12-20 15:52:00
 *
 */

public class job_HSTRecycle_operation_dsstaff implements CallBackInvoke{
	private static final Log log=LogFactory.getLog(job_HSTRecycle_operation_dsstaff.class);
	
	public void doCallBack(EliteBean eliteBean,String callBack,Map map,String body) {
	
	   log.debug("-------------------------start job_HSTRecycle_operation_timing 开始调用-----------------");

        String inData = "";
        String outData = "";
        String totalData = "";
		String totalData2 = "";
        String dataSourceID = "dataSource";


        try {
            List hst_recycle_ruleslist = eliteBean.chaxun_sql("select staff_id,hs_json from staff where hs_json is not null and hs_json!='' and hs_type is null  order by staff_id asc limit 1", "dataSource");//查询回收规则
            log.debug("hst_recycle_ruleslist:" + hst_recycle_ruleslist.size());
            if (hst_recycle_ruleslist.size() > 0) {
                int arrInt = hst_recycle_ruleslist.size();
                for (int i = 0; i < arrInt; i++) {
                    String hs_json = hst_recycle_ruleslist.get(i).get("hs_json");//回收规则id
                    String edit_staffid = hst_recycle_ruleslist.get(i).get("staff_id");//回收规则id

                    String sign_time = Instant.now().getEpochSecond();
                    log.debug("解析信息-" + "sign_time: " + sign_time);
                    String injson = hs_json
                    log.debug("injson:" + injson+"	edit_staffid:" + edit_staffid);
					
					//执行情况 1 在执行 null为待执行
					String updatestaffSQL = "update staff set hs_type=1 where staff_id= '"+edit_staffid+"'";
					def updatestaffSQLresult= eliteBean.update(updatestaffSQL, "dataSource");
					log.debug("更新staff的任务type参数："+updatestaffSQLresult);

                    totalData = Querypromocode(eliteBean, injson, dataSourceID);
						
                }

            }

            outData = "{\"result\":\"1\",\"message\":\"处理成功\",\"data\":[]}";


        } catch (Exception e) {
            log.error("接口处理异常" + e.getMessage());
            // 失败返回
            outData = "{\"result\":\"-1\",\"message\":\"处理失败(" + e.getMessage() + ")\",\"data\":[]}";
        }

        log.debug(outData);
    }

    //回收查询接口 URI:	aipHSTRecycle_operation
    public static String Querypromocode(EliteBean eliteBean, String injson, String dataSourceID) {

        long startTime = System.currentTimeMillis();
        log.debug("处理开始时间:" + startTime);

        long endTime = System.currentTimeMillis();

        String reJson = null;
        String tagname = "";
        try {
            String doURL = "";

            String sysurl = KHDBConfig.getAPIURL(eliteBean, "API-InnerDomain");//配置本地接口地址

            doURL = sysurl + "/aipHSTRecycle_operation_dsstaff";

            log.debug("doURL:" + doURL);
            Map<String, String> headMap = new HashMap<String, String>();
            headMap.put("Content-Type", "application/x-www-form-urlencoded");
            def getResult = Util.doHttpPostUseHead(doURL, injson, "UTF-8", 300000, 0, headMap);
            log.debug("getResult:" + getResult);
        } catch (Exception e) {
            log.error("接口处理异常" + e.getMessage());
            // 失败返回
            reJson = "{\"result\":\"-1\",\"message\":\"接口异常\",\\\"lastid\\\":\"0\"}";
        }
        return reJson;
    }

}
